package calc

import (
	"testing"

	"github.com/shopspring/decimal"
	"gitverse.ru/z3nyk3y/investcalc/internal/models"
)

func TestValidate(t *testing.T) {

	cases := []struct {
		name   string
		in     *models.Calculator
		expErr error
	}{
		{
			name: "ok",
			in: &models.Calculator{
				ToCalculate:    "TARGET",
				StartUpCapital: decimal.NewFromInt(100000),
				InvestPeriod: &models.InvestPeriod{
					Amount: 10,
					Period: "MONTHS",
				},
				Coefficient:    decimal.NewFromInt(100000),
				ReinvestPeriod: "MONTHLY",
			},
			expErr: nil,
		},
		{
			name: "target error",
			in: &models.Calculator{
				ToCalculate:    "TARGEfdsT",
				StartUpCapital: decimal.NewFromInt(100000),
				InvestPeriod: &models.InvestPeriod{
					Amount: 10,
					Period: "MONTH",
				},
				Coefficient:    decimal.NewFromInt(100000),
				ReinvestPeriod: "MONTHLY",
			},
			expErr: ErrInvalidTask,
		},
		{
			name: "nil target",
			in: &models.Calculator{

				StartUpCapital: decimal.NewFromInt(100000),
				InvestPeriod: &models.InvestPeriod{
					Amount: 10,
					Period: "MONTH",
				},
				Coefficient:    decimal.NewFromInt(100000),
				ReinvestPeriod: "MONTHLY",
			},
			expErr: ErrInvalidTask,
		},
		{
			name: "nil target",
			in: &models.Calculator{
				ToCalculate:    "START_UP_CAPITAL",
				StartUpCapital: decimal.NewFromInt(100000),
				InvestPeriod: &models.InvestPeriod{
					Amount: 10,
					Period: "MONTH",
				},
				Coefficient:    decimal.NewFromInt(100000),
				ReinvestPeriod: "MONTHLY",
			},
			expErr: ErrTargetValue,
		},
		{
			name: "empty Inv Per struct",
			in: &models.Calculator{
				ToCalculate: "TARGET",
				// Target:         decimal.NewFromInt(1000000),
				StartUpCapital: decimal.NewFromInt(100000),
				// InvestPeriod: &models.InvestPeriod{
				// 	Amount: 10,
				// 	Period: "MONTH",
				// },
				Coefficient:    decimal.NewFromInt(100000),
				ReinvestPeriod: "MONTHLY",
			},
			expErr: ErrInvestPeriodStruct,
		},
	}

	h := Handler{}

	for _, tCase := range cases {
		t.Run(tCase.name, func(t *testing.T) {
			err := h.validate(tCase.in)
			if err != tCase.expErr {
				t.Errorf("got %v, want %v", err, tCase.expErr)

			}
		})
	}
}
